package tw.cuttle;

import javax.servlet.ServletContext;

import tw.cuttle.bean.holder.BeanHolder;
import tw.cuttle.handler.ActionHandler;

public class CuttleContext {
    private static ThreadLocal<ServletContext> servletContext=new ThreadLocal<ServletContext>();
    private static ThreadLocal<ActionContext> actionContext=new ThreadLocal<ActionContext>();
    private static ProcessContext processContext;
    private static BeanHolder beanHolder;
    private static ActionHandler actionHandler;

    /**
     * @return the servletContext
     */
    public static ServletContext getServletContext() {
        return servletContext.get();
    }

    /**
     * @param servletContext the servletContext to set
     */
    public static void setServletContext(ServletContext servletContext) {
        CuttleContext.servletContext.set(servletContext);
    }

    /**
     * @return the actionHandler
     */
    public static ActionHandler getActionHandler() {
	if(actionHandler==null)actionHandler=new ActionHandler();
        return actionHandler;
    }

    /**
     * @param actionHandler the actionHandler to set
     */
    public static void setActionHandler(ActionHandler actionHandler) {
        CuttleContext.actionHandler = actionHandler;
    }

    /**
     * @return the processContext
     */
    public static ProcessContext getProcessContext() {
	if(processContext==null)processContext=new ProcessContext();
        return processContext;
    }

    /**
     * @param processContext the processContext to set
     */
    public static void setProcessContext(ProcessContext processContext) {
        CuttleContext.processContext = processContext;
    }

    /**
     * @return the beanHolder
     */
    public static BeanHolder getBeanHolder() {
	if(beanHolder==null)beanHolder=new BeanHolder();
        return beanHolder;
    }

    /**
     * @param beanHolder the beanHolder to set
     */
    public static void setBeanHolder(BeanHolder beanHolder) {
        CuttleContext.beanHolder = beanHolder;
    }

    /**
     * @return the actionContext
     */
    public static ActionContext getActionContext() {
	if(actionContext==null) CuttleContext.actionContext=new ThreadLocal<ActionContext>();
        return actionContext.get();
    }

    /**
     * @param actionContext the actionContext to set
     */
    public static void setActionContext(ActionContext actionContext) {
	if(actionContext==null) CuttleContext.actionContext=new ThreadLocal<ActionContext>();
        CuttleContext.actionContext.set(actionContext);
    }
}
